package com.linzm.creationaltype.factory01;

import com.linzm.creationaltype.factory01.Shape.Shape;
import com.linzm.creationaltype.factory01.shapefactory.AbstractShapeFactory;
import com.linzm.creationaltype.factory01.shapefactory.ShapeFactory;

import static com.linzm.creationaltype.factory01.enums.ShapeTypeEnum.CIRCLE;
import static com.linzm.creationaltype.factory01.enums.ShapeTypeEnum.RECTANGLE;
import static com.linzm.creationaltype.factory01.enums.ShapeTypeEnum.SQUARE;
import static com.linzm.creationaltype.factory01.enums.ShapeTypeEnum.HEXAGON;

/**
 * @Author zimingl
 * @Date 2023/4/15 12:31
 * @Description: FactoryPatternDemo
 */
public class FactoryPatternDemo {
    public static void main(String[] args) throws Exception {
        AbstractShapeFactory shapeFactory = new ShapeFactory();
        //获取 Circle 的对象，并调用它的 draw 方法
        Shape shape1 = shapeFactory.getShapeInstance(CIRCLE.name());
        //调用 Circle 的 draw 方法
        shape1.draw();
        //获取 Rectangle 的对象，并调用它的 draw 方法
        Shape shape2 = shapeFactory.getShapeInstance(RECTANGLE.name());
        //调用 Rectangle 的 draw 方法
        shape2.draw();
        //获取 Square 的对象，并调用它的 draw 方法
        Shape shape3 = shapeFactory.getShapeInstance(SQUARE.name());
        //调用 Square 的 draw 方法
        shape3.draw();
        // 自定义
        Shape hexagon = shapeFactory.getShapeInstance(HEXAGON.name());
        hexagon.draw();
    }
}
